<?php
	include_once 'isLogin.php';
	$servicec=new service(); //服务类
	$id=$_GET['id'];
	$smarty->assign('id',$id);

	$table="zs_service_album";	//相册

	
	if($_GET['action']=="getImg"){
		$img = $commonc->getInfo($table, $_POST['img_id'],"img,service_id");
		$num = $commonc->getNum($table." where service_id=".$img['service_id']);
		echo json_encode(array('img'=>$img['img'],'num'=>$num));
		exit();
	}
	
	if($_GET['action']=='sort'){
		$arr = array('sort'=>$_POST['sort']);
		$commonc->update($table, $arr, "id='".$_POST['img_id']."'");
		exit();
	}
	
	if($_GET['action']=='delImg'){
		$img = $commonc->getInfo($table, $_POST['img_id'],'img');
		@unlink("../upload/service/large/".$img['img']);
		@unlink("../upload/service/small/".$img['img']);
		echo $commonc->del($table, $_POST['img_id'].",");
		exit();
	}

	
	if(isset($_FILES["imgs"]) && is_uploaded_file($_FILES["imgs"]["tmp_name"]) && $_FILES["imgs"]["error"] == 0 && $_GET['id']!=false) {
	
		//设置路径
		$annexFolder = "../upload/service/large/";
		$smallFolder = "../upload/service/small/";;
		
		//上传新图
		$upimg = new uploadImg();
		$img = $upimg->upLoad('imgs',$annexFolder);
		//小图
		$upimg->smallImg($annexFolder.$img,$smallFolder,'','200','200',true);
	
		//总条数
		$sql = $table." where service_id='".$_GET['id']."'";
		$sort = $commonc->getNum($sql)+1;
		
		//插入数据
		$arr = array('service_id'=>$_GET['id'],'img'=>$img,'sort'=>$sort);
		$commonc->insert($table, $arr);
		$img_id = $commonc->insert_id();
		echo $img_id;
		exit();
	}

	
	//获得数据
	if($_GET['id']!=false){
		//图片列表
		$where=" AND s.service_id=".$id;
		$img = $servicec->service_album_list($where);
		$smarty->assign('img',$img['result']);
	}
	
	$smarty->display("service_album.html");
?>